﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Text;
using hes.models;
using hes.controllers;
using System.Collections;


namespace hes.data_access
{
    //This class handles all data access between the application and the
    //educator table in the database.
    class EducatorDAO
    {
        private SqlConnection ed_connection; // = prototype123.Program.connect.GetConnection();

        public EducatorDAO(SqlConnection connection)
        {
            ed_connection = connection;

        }


        /// <precondition>System has logged in and needs all educator info</precondition>
        /// <summary>
        /// Get all educator info given an Educator's ID number
        /// </summary>
        /// <param name="id">ID# of the current Educator</param>
        /// <returns>Educator object - an object containing all info about an Educator</returns>
        /// <postconditions>System has an educator object with all attributes populated</postconditions>
        public Educator GetEducator(int id)
        {
            Educator ed = new Educator();
            SqlCommand getEd;
            ArrayList list = new ArrayList();

            try
            {
                getEd = new SqlCommand("SELECT * FROM EDUCATOR WHERE EDU_ID = " + id, ed_connection);
                SqlDataReader reader = getEd.ExecuteReader();
                while (reader.Read())
                {
                    ed.EducatorID = Convert.ToInt32(reader["EDU_ID"]);
                    ed.FirstName = (string)reader["FNAME"];
                    ed.LastName = (string)reader["LNAME"];
                    ed.FormalSalutation = (string)reader["FORMAL_SAL"];
                    ed.InformalSalutation = (string)reader["INFORMAL_SAL"];
                    ed.HomePhone = (string)reader["HOME_PHONE"];
                    ed.EmailAddress = (string)reader["EMAIL_ADDR"];
                    ed.SpouseFirstName = (string)reader["SPOUSE_FNAME"];
                    ed.SpouseLastName = (string)reader["SPOUSE_LNAME"];
                }
                reader.Close();
            }
            catch { ed = null; }
            return ed;
        }

    }
}
